$(function(){
	//初始化
	init();
	bindFun();
});
var policyRef; //保单号
var preprintedNo;
var contractId; //照会号
var productName; //主险名称
var agentName;
var agentCode;
var phName;
var result;
function init(){
	contractId=sessionStorage.contractId;
	policyRef=sessionStorage.policyRef;
	$("#policyRef").html(policyRef);
	
	
	//初始化NEWTOUCH数据
	padMarketing.ajaxNormal(
			"/pad_marketing/note/initMyContent.action",
			{"contractId" :contractId},
			function(data){
				result = data.result;
			}
	);
	
	
	var C = getQueryString("C");
	var M = getQueryString("M");
	var O = getQueryString("O");
	var D = getQueryString("D");
	var S = getQueryString("S");
	var H = getQueryString("H");
	var L = getQueryString("L");
	var decla = getQueryString("decla");
	var html="";
	var num=1;
	var wenben='';
	//处理界面的数据
	if(decla=="Y"){
		html+='<p class="font-18 lh-45">1.签署了一份声明</p>';
		html+='<textarea class="form-control" rows="5" disabled="disabled" placeholder="无法提供近三年的收入凭证。">'+sessionStorage.declaraction+'</textarea>';
		wenben=sessionStorage.declaraction;
		num++;
	}
	if(C!=0&&C!=null){
		html+='<p class="font-18 lh-45">'+num+'.补充了告知声明书资料'+C+'张</p>';
		num++;
	}
	if(M!=0&&M!=null){
		html+='<p class="font-18 lh-45">'+num+'.补充了财务类资料'+M+'张</p>';
		num++;
	}
	if(O!=0&&O!=null){
		html+='<p class="font-18 lh-45">'+num+'.补充了身份识别证件类资料'+O+'张</p>';
		num++;
	}
	if(D!=0&&D!=null){
		html+='<p class="font-18 lh-45">'+num+'.补充了其他医务类资料'+D+'张</p>';
		num++;
	}
	if(S!=0&&S!=null){
		html+='<p class="font-18 lh-45">'+num+'.补充了投保声明文件类资料'+S+'张</p>';
		num++;
	}
	if(H!=0&&H!=null){
		html+='<p class="font-18 lh-45">'+num+'.补充了高额问卷类资料'+H+'张</p>';
		num++;
	}
	if(L!=0&&L!=null){
		html+='<p class="font-18 lh-45">'+num+'.补充了其他监管类资料'+L+'张</p>';
		num++;
	}
	$("#content").append(html);
	//新建pdf
	padMarketing.ajaxNormal(
			"/pad_marketing/note/getProductName.action",
				{"contractId":contractId},
				function(data){
					productName =  data.PROUCT_NAME;
					agentCode = data.SL_AGENT_CODE;
					agentName = data.SL_AGENT_NAME;
					phName = data.PH_NAME;
					preprintedNo = data.PRE_PRINTED_NO;
					$("#productName").html(productName);
					$("#agentCode").html(agentCode);
					$("#agentName").html(agentName);
					$("#phName").html(phName);
					padMarketing.ajaxNormal(
							"/pad_marketing/note/createPdf.action",
							{	'policyRef':policyRef ,
								'agentName':agentName,
								'agentCode':agentCode,
								'phName':phName,
								'html':html,
								'wenben':wenben,
								'type':'1169',
								'contractId':contractId,
								'productName':productName},
							function(data){
									setTimeout(function(){
										initSign(policyRef,"4");
									}, 2000);
									
								}
					);
				}
		);
};
function bindFun(){
	
};

function returnUrl(){
	var url = getQueryString("url");
	if(url==null){
		location.href="/pad_marketing/index/index.action";
		return;
	}
	location.href=url;
}

//壳回调本地方法  展示签字     src是数据  pdfNum是pdf界面  siger是0 imgNum是img
function showSign(src,pdfNum,siger,imgNum){
	var num = imgNum.substr(3,1);
	$("#sign"+num).hide();
	var img=document.getElementById(imgNum);
	src = 'data:image/png;base64,' + src;
	img.src = src;
	if(myScroll)
		myScroll.refresh();
}
//拍照回调
var src3 = "";
var src4 ="";
function showPhoto(src,imgNum){
	if('pho1'==imgNum)src3 = src;
	if('pho2'==imgNum)src4 = src;
	var img=document.getElementById(imgNum);
	src = 'data:image/png;base64,' + src;			
	img.src = src;
	if(myScroll)
		myScroll.refresh();
}

function next(){
	//投保单--投保人签名
	var sign1 = $("#sign1").attr("style");
	if('display: none;'!=sign1 ){
		alertMsg('请完成投保人签名！');
		return;
	}
	//校验投保单--投保人拍照
	if(''==src3){
		alertMsg('请完成投保人清晰的胸部以上正面照拍摄！');
		return;
	}
	
	//投保单--经纪人/营销人员签名
	var sign2 = $("#sign2").attr("style");
	if('display: none;'!=sign2){
		alertMsg('请完成营销人员签名！');
		return;
	}
	//校验投保单--经纪人/营销人员拍照
	if(''==src4){
		alertMsg('请完成营销人员清晰的胸部以上正面照拍摄！');
		return;
	}
	//首先上传影像 
	finishSign("doSign");
}

function doSign(pdf5){
	var photoList1 = [src3,src4];
	var pdfMessageList = [];
	pdfMessageList.push({"pdfType":"1169","encode":pdf5,"photoList":photoList1});
	var params={"policyRef":policyRef,"pdfMessageList":pdfMessageList,"insured":contractId};
	
	padMarketing.ajaxNormal('/pad_marketing/note/NoteAffirmCA.action',params,
			function(data){
		
		
		var typeList=[];
		typeList.push("1152");
		typeList.push("1160");
		typeList.push("1163");
		typeList.push("1153");
		typeList.push("1159");
		typeList.push("1154");
		typeList.push("1171");
		typeList.push("NL4003");
		typeList.push("1169");
		//图片全部上传
		padMarketing.ajaxNormal(
				"/pad_marketing/note/uploadAll.action",
				{	'typeList' : typeList,
					'policyRef':policyRef,
					'preprintedNo':preprintedNo,
					'contractId':contractId},
				function(data){
						changeState();
					}
		);
	},
			function(data){
				
			},
			true,//是否异步
			true,//是否显示加载电波图
			'不用美图都那么帅，不过字该练练啦！'//电波图中的话术
	);

}
function changeState(){
	result.allOk="Y";
	padMarketing.ajaxNormal(
			"/pad_marketing/note/updateMyContent.action",
			result,
			function(data){
				alertMsg("当前照会回复完成",0,function(){
					location.href="/pad_marketing/index/index.action";
				});
			}
	);
}